#include "ClientNetworkManager.h"

#include <assert.h>
#include <iostream>
ClientNetworkManager::ClientNetworkManager(void)
{
	Init();
}
ClientNetworkManager::~ClientNetworkManager(void)
{
	Shutdown();
}

void ClientNetworkManager::Init(void)
{
	sockaddr_in addr = {0};

	addr.sin_addr.S_un.S_addr = inet_addr(SERVER_ADDRESS);
	addr.sin_family = AF_INET;
	addr.sin_port = htons(SERVER_PORT);
	int ret = connect(m_socket, (SOCKADDR*)&addr, sizeof(addr));
	assert(ret != SOCKET_ERROR);
	RecvThreadArgs* args = new RecvThreadArgs();
	args->mgr = this;
	args->socket = m_socket;
	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)SocketRecvThread, args, 0, 0);
}
void ClientNetworkManager::Shutdown(void)
{
	m_isRunning = false;
}
void ClientNetworkManager::SendToServer(Packet* packet)
{
	SendPacket(packet, m_socket);
}